package com.crm.system.controller.contactManager;

import com.crm.common.model.DataResponse;
import com.crm.common.model.DhPageInfo;
import com.crm.common.model.DhResponse;
import com.crm.common.model.Enum.ResponseCodeEnum;
import com.crm.model.entity.contactManager.*;
import com.crm.model.qo.contactManager.ContactInformationManyPeopleQO;
import com.crm.model.vo.contactManager.*;
import com.crm.system.service.contactManager.ContactInformationManyPeopleService;
import com.crm.system.service.contactManager.ContactService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 系方式一机多用
 */
@RestController
@RequestMapping("/contactInformationManyPeople")
@Slf4j
public class ContactInformationManyPeopleController {

    @Autowired
    private ContactService contactService;

    @Autowired
    private ContactInformationManyPeopleService contactInformationManyPeopleService;


    /**
     * 联系联系方式一机多用
     *
     * @param pageIndex 页码
     * @param pageSize  分页大小
     * @param sortName  排序列名字
     * @param sortOrder 排序规则(asc/desc)
     * @param contactInformationManyPeopleQO 查询条件
     * @return
     */
    @PostMapping("/contactInformationManyPeopleList")
    public DataResponse contactInformationManyPeopleList(HttpServletRequest request,
                                                         @RequestParam(value = "pageIndex", required = true) Integer pageIndex,//页码
                                                         @RequestParam(value = "pageSize", required = true) Integer pageSize,//分页大小
                                                         @RequestParam(value = "sortName", required = false) String sortName,//排序列名字
                                                         @RequestParam(value = "sortOrder", required = false) String sortOrder,//排序规则(asc/desc)
                                                         ContactInformationManyPeopleQO contactInformationManyPeopleQO//查询条件
    ) {
        try {
            DhPageInfo<ContactInformationManyPeopleVO> list = contactInformationManyPeopleService.contactInformationManyPeopleList(pageIndex, pageSize, contactInformationManyPeopleQO, sortName, sortOrder);
            return new DhResponse(ResponseCodeEnum.OK.getResponseCode(), list);
        } catch (Exception e) {
            log.error("contactInformationManyPeople contactInformationManyPeopleList error:", e);
            return new DhResponse(ResponseCodeEnum.ERROR.getResponseCode());
        }
    }

    /**
     * 新增联系方式人
     * @param contactInformationManyPeople
     * @return
     */
    @PostMapping("/addContactInformationManyPeople")
    public DataResponse addContactInformationManyPeople(@RequestBody ContactInformationManyPeople contactInformationManyPeople) {
        try {
            String result = contactInformationManyPeopleService.addContactInformationManyPeople(contactInformationManyPeople);
            return new DhResponse(ResponseCodeEnum.OK.getResponseCode(),result);
        } catch (Exception e) {
            log.error("contactInformationManyPeople addContactInformationManyPeople error:", e);
            return new DhResponse(ResponseCodeEnum.SERVICE_ERROR.getResponseCode());
        }
    }

    /**
     * 联系人名称管理信息
     * @param contactInformationManyPeopleId 联系方式一机多用id
     * @param bs 0显示未废止的  1显示全部的
     * @return
     */
    @PostMapping("/contactInformationManyPeopleNameList")
    public DataResponse contactInformationManyPeopleNameList(HttpServletRequest request,
                                                             @RequestParam(value = "pageIndex", required = false) Integer pageIndex,//页码
                                                             @RequestParam(value = "pageSize", required = false) Integer pageSize,//分页大小
                                                             @RequestParam(value = "contactInformationManyPeopleId") String contactInformationManyPeopleId,
                                                             @RequestParam(value = "bs") String bs
    ) {
        try {
            DhPageInfo<ContactInformationManyPeopleName> pageInfo = contactInformationManyPeopleService.contactInformationManyPeopleNameList(contactInformationManyPeopleId,bs,pageIndex,pageSize);
            return new DhResponse(ResponseCodeEnum.OK.getResponseCode(),pageInfo);
        } catch (Exception e) {
            log.error("contactInformationManyPeople contactInformationManyPeopleNameList error:", e);
            return new DhResponse(ResponseCodeEnum.ERROR.getResponseCode());
        }
    }

    /**
     * 新增联系人名称
     * @param name
     * @return
     */
    @PostMapping("/addContactInformationManyPeopleName")
    public DataResponse addContactInformationManyPeopleName(@RequestBody ContactInformationManyPeopleName name) {
        try {
            String result = contactInformationManyPeopleService.addContactInformationManyPeopleName(name);
            return new DhResponse(ResponseCodeEnum.OK.getResponseCode(),result);
        } catch (Exception e) {
            log.error("contactInformationManyPeople name error:", e);
            return new DhResponse(ResponseCodeEnum.SERVICE_ERROR.getResponseCode());
        }
    }

    /**
     * 切换联系人名称
     * @param name
     * @return
     */
    @PostMapping("/switchName")
    public DataResponse switchName(@RequestBody ContactInformationManyPeopleName name) {
        try {
            Boolean result = contactInformationManyPeopleService.switchName(name);
            if (result) {
                return new DhResponse(ResponseCodeEnum.OK.getResponseCode());
            }
            return new DhResponse(ResponseCodeEnum.SERVICE_ERROR.getResponseCode());
        } catch (Exception e) {
            log.error("contactInformationManyPeople switchName error:", e);
            return new DhResponse(ResponseCodeEnum.SERVICE_ERROR.getResponseCode());
        }
    }

    /**
     * 废止联系人名称
     * @param name
     * @return
     */
    @PostMapping("/abolishName")
    public DataResponse abolishName(@RequestBody ContactInformationManyPeopleName name) {
        try {
            Boolean result = contactInformationManyPeopleService.abolishName(name);
            if (result) {
                return new DhResponse(ResponseCodeEnum.OK.getResponseCode());
            }
            return new DhResponse(ResponseCodeEnum.SERVICE_ERROR.getResponseCode());
        } catch (Exception e) {
            log.error("contactInformationManyPeople abolishName error:", e);
            return new DhResponse(ResponseCodeEnum.SERVICE_ERROR.getResponseCode());
        }
    }






}
